/*
 * Not.cpp
 *
 * Created on: 05-05-2014
 *     Author: A.W. Janisse
 *
 * Version 1.0: 24-05-2014, Final release
 */

#include <sstream>
#include "Not.h"

Not::Not(int x, int y, string type)
:OneEntry(x, y, type)
{
}

int Not::getOutputValue()
{
    if(getEntry(0) != NULL)
        return !getEntry(0)->getOutputValue();
    else
        return 1;
}

string Not::getDrawingInstruction()
{
    stringstream result;

    int v1 = 0;
    if(getEntry(0) != NULL){
        v1 = getEntry(0)->getOutputValue();

        result << "connection"; // gate of connection
        result << ",";
        result << (v1 ? "H" : "L");
        result << ",";
        result << getEntry(0)->getX() + 8;
        result << ",";
        result << getEntry(0)->getY() + 3;
        result << ",";
        result << getX();
        result << ",";
        result << getY() + 3;
        result << "\n";
    }

    result << "gate";           // gate of connection
    result << ",";
    result << getNumber();      // nummer
    result << ",";
    result << getType();        // type
    result << ",";
    result << getX();           // x positie
    result << ",";
    result << getY();           // y positie
    result << ",";
    result << 1;                // One input
    result << ",";
    result << (v1 ? "H" : "L"); // value input 1
    result << ",";
    result << "L";              // value input 2
    result << ",";
    result << (getOutputValue() ? "H" : "L"); // value output
    result << "\n";

    return result.str();
}
